package com.jwater.core.common;

import java.io.UnsupportedEncodingException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @description: 字符串和bytes的转化支持，以及字符编译的统一定义
 * @author: jnner
 * @createDate: 2021/2/5
 * @version: 1.0
 */
public class S {
    protected static Logger logger = LoggerFactory.getLogger(S.class);

    public static final String charset = "UTF-8";

    public static final short NET_VERSION = 1;

    public static String newString(byte[] data) {
        try {
            return new String(data, charset);
        } catch (UnsupportedEncodingException e) {
            logger.error(e.toString(), e);
        }
        return null;
    }

    public static byte[] toBytes(String value) {
        try {
            return value.getBytes(charset);
        } catch (UnsupportedEncodingException e) {
            logger.error(e.toString(), e);
        }
        return null;
    }
}
